;******************************************************************************************************
;ISInstaller 20100325 by eljorgejones 
;******************************************************************************************************

variable string MYUPDATECONFIGPATH="${LavishScript.HomeDirectory}/Scripts/EQ/Config"
variable string MYUPDATEUIPATH="${LavishScript.HomeDirectory}/Scripts/EQ/UI"
variable string MYUPDATESCRIPTPATH="${LavishScript.HomeDirectory}/Scripts/EQ"
variable string WINDOWELEMENT=deployui
variable string TABCONTROLELEMENT=deploytab
variable string sdeploy
variable string sversion
variable string cversion
variable string sfilename1
variable string sfilename2
variable string sfilename3
variable string sfilename4
variable string sfilename5
variable string sfilename6
variable string sfilename7
variable string sfilename8
variable string sfilename9
variable string sfilename10
variable string sfilename11
variable string sfilename12
variable string sfilename13
variable string sfilename14
variable string sfilename15
variable string sfilename16
variable string sfilename17
variable string sfilename18
variable string sfilename19
variable string sfilename20
variable string lfilename1
variable string lfilename2
variable string lfilename3
variable string lfilename4
variable string lfilename5
variable string lfilename6
variable string lfilename7
variable string lfilename8
variable string lfilename9
variable string lfilename10
variable string lfilename11
variable string lfilename12
variable string lfilename13
variable string lfilename14
variable string lfilename15
variable string lfilename16
variable string lfilename17
variable string lfilename18
variable string lfilename19
variable string lfilename20

variable settingsetref supdate

function main()
{
	call makedirs
	call downloadmanifest
	do
	{
		if !${QueuedCommands}
		WaitFrame
	    else
		ExecuteQueued
	}
	while 1
}
function makedirs()
{
	declare MyButtonPath filepath script "${LavishScript.HomeDirectory}/Scripts/EQ"
	declare MyUIPath filepath script "${LavishScript.HomeDirectory}/Scripts/EQ/UI"
	declare MyConfigPath filepath script "${LavishScript.HomeDirectory}/Scripts/EQ/Config"
	declare MyBackupPath filepath script "${LavishScript.HomeDirectory}/Scripts/EQ/BackUp"
	declare MyScript filepath script "${LavishScript.HomeDirectory}/Scripts/"
	
	if ${MyButtonPath(exists)} == FALSE
	{
	echo ${MyButtonPath}
	}
	else
	{
	MyScript:MakeSubdirectory[EQ]
	}
	if ${MyUIPath(exists)} == FALSE
	{
	echo ${MyUIPath}
	}
	else
	{
	MyScript:MakeSubdirectory[EQ/UI]
	}
	if ${MyConfigPath(exists)} == FALSE
	{
	echo ${MyConfigPath}
	}
	else
	{
	MyScript:MakeSubdirectory[EQ/Config]
	}
	if ${MyBackUpPath(exists)} == FALSE
	{
	echo ${MyBackUpPath}
	}
	else
	{
	MyScript:MakeSubdirectory[EQ/BackUp]
	}
	wait 20
	return
}
;************************************************************************************************************************
;following myupdate.iss snippets by eljorgejones 20100310a
;************************************************************************************************************************
function downloadmanifest()
{
	sdeploy:Set[http://dl.dropbox.com/u/4241804/Release/UI/updateconfig.xml]		
	Execute httpget -file "${MYUPDATECONFIGPATH}/updateconfig.xml" ${sdeploy}
	wait 40
	echo Loading Settings contained in updateconfig.xml!
	call UpdateSettings
	call deployupdate
	call startitup
}
function UpdateSettings()
{
	LavishSettings:AddSet[Updates]
	LavishSettings[Updates]:Clear
	LavishSettings[Updates]:AddSet[Update]
	supdate:Set[${LavishSettings[Updates].FindSet[Update]}]
	LavishSettings[Updates]:Import["${MYUPDATECONFIGPATH}/updateconfig.xml"]
		
	sversion:Set[${supdate.FindSetting[sversion,Check for Updates]}]
	sfilename1:Set[${supdate.FindSetting[sfilename1,]}]
	sfilename2:Set[${supdate.FindSetting[sfilename2,]}]
	sfilename3:Set[${supdate.FindSetting[sfilename3,]}]
	sfilename4:Set[${supdate.FindSetting[sfilename4,]}]
	sfilename5:Set[${supdate.FindSetting[sfilename5,]}]
	sfilename6:Set[${supdate.FindSetting[sfilename6,]}]
	sfilename7:Set[${supdate.FindSetting[sfilename7,]}]
	sfilename8:Set[${supdate.FindSetting[sfilename8,]}]
	sfilename9:Set[${supdate.FindSetting[sfilename9,]}]
	sfilename10:Set[${supdate.FindSetting[sfilename10,]}]
	sfilename11:Set[${supdate.FindSetting[sfilename11,]}]
	sfilename12:Set[${supdate.FindSetting[sfilename12,]}]
	sfilename13:Set[${supdate.FindSetting[sfilename13,]}]
	sfilename14:Set[${supdate.FindSetting[sfilename14,]}]
	sfilename15:Set[${supdate.FindSetting[sfilename15,]}]
	sfilename16:Set[${supdate.FindSetting[sfilename16,]}]
	sfilename17:Set[${supdate.FindSetting[sfilename17,]}]
	sfilename18:Set[${supdate.FindSetting[sfilename18,]}]
	sfilename19:Set[${supdate.FindSetting[sfilename19,]}]
	sfilename20:Set[${supdate.FindSetting[sfilename20,]}]
	lfilename1:Set[${supdate.FindSetting[lfilename1,]}]
	lfilename2:Set[${supdate.FindSetting[lfilename2,]}]
	lfilename3:Set[${supdate.FindSetting[lfilename3,]}]
	lfilename4:Set[${supdate.FindSetting[lfilename4,]}]
	lfilename5:Set[${supdate.FindSetting[lfilename5,]}]
	lfilename6:Set[${supdate.FindSetting[lfilename6,]}]
	lfilename7:Set[${supdate.FindSetting[lfilename7,]}]
	lfilename8:Set[${supdate.FindSetting[lfilename8,]}]
	lfilename9:Set[${supdate.FindSetting[lfilename9,]}]
	lfilename10:Set[${supdate.FindSetting[lfilename10,]}]
	lfilename11:Set[${supdate.FindSetting[lfilename11,]}]
	lfilename12:Set[${supdate.FindSetting[lfilename12,]}]
	lfilename13:Set[${supdate.FindSetting[lfilename13,]}]
	lfilename14:Set[${supdate.FindSetting[lfilename14,]}]
	lfilename15:Set[${supdate.FindSetting[lfilename15,]}]
	lfilename16:Set[${supdate.FindSetting[lfilename16,]}]
	lfilename17:Set[${supdate.FindSetting[lfilename17,]}]
	lfilename18:Set[${supdate.FindSetting[lfilename18,]}]
	lfilename19:Set[${supdate.FindSetting[lfilename19,]}]
	lfilename20:Set[${supdate.FindSetting[lfilename20,]}]
	return
}
function startitup()
{
	run ./scripts/eq/eqisbuttons.iss
	wait 40
	endscript isinstaller
}
function deployupdate()
{
	
	MessageBox "This will download the latest files from the server. Check console for update messages and any errors (default console key is ~}.  Click OK to continue!" 
	declare MyWait filepath "${MYUPDATESCRIPTPATH}"
	echo Downloading new files!
	ISBoxerUI:PopupText["Download starting",5000]
	httpget -file "./EQ/${lfilename1}" ${sfilename1} (exists)
	httpget -file "./EQ/${lfilename2}" ${sfilename2}
	httpget -file "./EQ/${lfilename3}" ${sfilename3}
	httpget -file "./EQ/UI/${lfilename4}" ${sfilename4}
	httpget -file "./EQ/UI/${lfilename5}" ${sfilename5}
	httpget -file "./EQ/UI/${lfilename6}" ${sfilename6}
	httpget -file "./EQ/UI/${lfilename7}" ${sfilename7}
	httpget -file "./EQ/UI/${lfilename8}" ${sfilename8}
	httpget -file "./EQ/UI/${lfilename9}" ${sfilename9}
	httpget -file "./EQ/UI/${lfilename10}" ${sfilename10}
	httpget -file "./EQ/UI/${lfilename11}" ${sfilename11}
	httpget -file "./EQ/UI/${lfilename12}" ${sfilename12}
	httpget -file "./EQ/UI/${lfilename13}" ${sfilename13}
	httpget -file "./EQ/UI/${lfilename14}" ${sfilename14}
	httpget -file "./EQ/UI/${lfilename15}" ${sfilename15}
	httpget -file "./EQ/UI/${lfilename16}" ${sfilename16}
	httpget -file "./EQ/UI/${lfilename17}" ${sfilename17}
	httpget -file "./EQ/UI/${lfilename18}" ${sfilename18}
	httpget -file "./EQ/${lfilename19}" ${sfilename19}
	while ${MyWait.FileExists[\/shitbuilder.iss]} == FALSE
	{
		wait 10
		if ${MyWait.FileExists[\/shitbuilder.iss]} == TRUE
		{
		echo Done
		break
		}
	}
	
	echo Update complete
	ISBoxerUI:PopupText["Update Is Complete",5000]
	MessageBox "Install complete. Check console for update messages and any errors (default console key is ~}.  Click OK Launch EQ Hotbuttons!" 
	return
}
